/**
*
* @file asn1.h
*
* @brief function declarations and defines for Encoding/Decoding BER messages
*
* Copyright ?2011 HID Corporation.  All rights reserved.
*
* This software is protected by copyright law and international treaties.
* Any unauthorized reproduction, distribution or use of the software is prohibited.
*
*/

#ifndef _asn1_h
#define _asn1_h

#define ASN1_TAG_EOC             	0
#define ASN1_TAG_BOOLEAN         	1
#define ASN1_TAG_INTEGER         	2
#define ASN1_TAG_BITSTRING       	3
#define ASN1_TAG_OCTETSTRING     	4
#define ASN1_TAG_NULL            	5
#define ASN1_TAG_OID             	6
#define ASN1_TAG_REAL            	9
#define ASN1_TAG_ENUMERATED      	10
#define ASN1_TAG_UTF8STRING      	12
#define ASN1_TAG_SEQUENCE        	16
#define ASN1_TAG_SET             	17
#define ASN1_TAG_NUMERICSTRING   	18
#define ASN1_TAG_PRINTABLESTRING 	19
#define ASN1_TAG_T61STRING       	20
#define ASN1_TAG_VIDEOTEXTSTRING 	21
#define ASN1_TAG_IA5STRING       	22
#define ASN1_TAG_UTCTIME         	23
#define ASN1_TAG_GENERALIZEDTIME 	24
#define ASN1_TAG_GRAPHICSTRING   	25
#define ASN1_TAG_VISIBLESTRING   	26
#define ASN1_TAG_GENERALSTRING   	27
#define ASN1_TAG_UNIVERSALSTRING 	28
#define ASN1_TAG_BMPSTRING       	30
#define ASN1_TAG_MASK            	0x1F
#define ASN1_TAG_LONGFORM        	0x1F

#define ASN1_COUNTER32				0x41

#define ASN1_CLASS_UNIVERSAL   		0x00
#define ASN1_CLASS_APPLICATION 		0x40
#define ASN1_CLASS_CONTEXT     		0x80
#define ASN1_CLASS_PRIVATE     		0xC0
#define ASN1_CLASS_MASK        		0xC0

#define ASN1_CHOICE_CONSTRUCTED     (ASN1_CLASS_CONTEXT | ASN1_CONSTRUCTED)
#define ASN1_CHOICE_PRIMITIVE		(ASN1_CLASS_CONTEXT)

#define ASN1_PRIMITIVE   			0x00
#define ASN1_CONSTRUCTED 			0x20

#define ASN1_LENGTH_LONGFORM 		0x80
#define ASN1_LENGTH_MASK 			0x7F

#define ASN1_NULL_OBJECT            0x0500

#define OID_VALUE_LENGTH(INPUT_LENGTH)		(ROUND_UP_N(8, (1 + ((INPUT_LENGTH) * 8) + (INPUT_LENGTH)), uint16_t) / 8)
/*
extern void asn1_buildNull(uint8_t** result, uint16_t* resultLength);
extern void asn1_buildOid(uint8_t* oid, uint16_t oidLength, uint8_t** result, uint16_t* resultLength);
extern void asn1_buildOctectString(uint8_t* Data, uint16_t length, uint8_t** result, uint16_t* resultLength);

extern void asn1_buildU1Integer(uint8_t value, uint8_t** result, uint16_t* resultLength);
extern void asn1_buildU2Integer(uint16_t value, uint8_t** result, uint16_t* resultLength);
extern void asn1_buildU4Integer(uint32_t value, uint8_t** result, uint16_t* resultLength);
extern void asn1_buildInteger(uint8_t* value, uint16_t valueLength, uint8_t** result, uint16_t* resultLength);
*/
extern uint8_t* asn1_openTag1(uint8_t tag, uint8_t** result, uint16_t* resultLength);
uint8_t* asn1_openTag2(uint8_t tag, uint8_t skipLength, uint8_t** result, uint16_t* resultLength);

extern void asn1_closeTag1(uint8_t* lengthPositionInResultBuffer, uint8_t* result);
void asn1_closeTag2(uint8_t lengthSize, uint8_t* lengthPositionInResultBuffer, uint8_t* result);

//extern void asn1_closeTag_DER(uint8_t* lengthPositionInResultBuffer, uint8_t** result, uint16_t* resultLength);
/*
extern void asn1_append(uint8_t* Data, uint16_t dataLength, uint8_t** result, uint16_t* resultLength);

extern uint8_t asn1_integerAsU1(uint8_t* Data, uint16_t length);
extern uint16_t asn1_integerAsU2(uint8_t* Data, uint16_t length);
extern uint32_t asn1_integerAsU4(uint8_t* Data, uint16_t length);

extern uint8_t asn1_booleanAsU1(uint8_t* Data, uint16_t length);

extern int8_t asn1_integerCompare(uint8_t* int1, uint8_t int1Length, uint8_t* int2, uint8_t int2Length);

extern uint16_t asn1_buildOIDValue(uint8_t* value, uint16_t valueLength, uint8_t* encodedValue, uint16_t encodedValueMaxLength);

#ifdef INTERNAL_VALIDATION
extern void asn1_internalValidation(void);
#endif
*/
#endif
